package com.docmanage.web.controller.am;

import com.docmanage.am.domain.AmFolder;
import com.docmanage.am.service.impl.AmFolderService;
import com.docmanage.common.annotation.Log;
import com.docmanage.common.core.controller.BaseController;
import com.docmanage.common.core.domain.AjaxResult;
import com.docmanage.common.enums.BusinessType;
import com.docmanage.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件夹Controller
 * 
 * @author pointLion
 * @date 2023-06-18
 */
@RestController
@RequestMapping("/am/amFolder")
public class AmFolderController extends BaseController
{
    @Autowired
    private AmFolderService amFolderService;

    /**
     * 查询文件夹列表
     */
    @PreAuthorize("@ss.hasPermi('am:amFolder:list')")
    @GetMapping("/list")
    public AjaxResult list(AmFolder amFolder)
    {
        List<AmFolder> list = amFolderService.selectAmFolderList(amFolder);
        return AjaxResult.success(list);
    }

    /**
     * 导出文件夹列表
     */
    @PreAuthorize("@ss.hasPermi('am:amFolder:export')")
    @Log(title = "文件夹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AmFolder amFolder)
    {
        List<AmFolder> list = amFolderService.selectAmFolderList(amFolder);
        ExcelUtil<AmFolder> util = new ExcelUtil<AmFolder>(AmFolder.class);
        util.exportExcel(response, list, "文件夹数据");
    }

    /**
     * 获取文件夹详细信息
     */
    @PreAuthorize("@ss.hasPermi('am:amFolder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amFolderService.selectAmFolderById(id));
    }

    /**
     * 新增文件夹
     */
    @PreAuthorize("@ss.hasPermi('am:amFolder:add')")
    @Log(title = "文件夹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmFolder amFolder)
    {
        return toAjax(amFolderService.insertAmFolder(amFolder));
    }

    /**
     * 修改文件夹
     */
    @PreAuthorize("@ss.hasPermi('am:amFolder:edit')")
    @Log(title = "文件夹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmFolder amFolder)
    {
        return toAjax(amFolderService.updateAmFolder(amFolder));
    }

    /**
     * 删除文件夹
     */
    @PreAuthorize("@ss.hasPermi('am:amFolder:remove')")
    @Log(title = "文件夹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amFolderService.deleteAmFolderByIds(ids));
    }



    @GetMapping("/treeselect")
    public AjaxResult treeselect(AmFolder amFolder)
    {
        List<AmFolder> list = amFolderService.selectAmFolderList(amFolder);
        return AjaxResult.success(amFolderService.buildTreeSelect(list));
    }



}
